import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { DeviceRepositoryModule } from '@app/db/device-repository/device-repository.module';
import { UserRepositoryModule } from '@app/db/user-repository/user-repository.module';
import { RechargeOptionRepositoryModule } from '@app/db/recharge-option-repository/recharge-option-repository.module';
import { DeviceTypeRepositoryModule } from '@app/db/device-type-repository/device-type-repository.module';
import { WaterTestRepositoryModule } from '@app/db/water-test-repository/water-test-repository.module';
import { WaterBillsRepositoryModule } from '@app/db/water-bills-repository/water-bills-repository.module';
import { CleanRecordRepositoryModule } from '@app/db/clean-record-repository/clean-record-repository.module';
import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';
import { RechargeOrderRepositoryModule } from '@app/db/recharge-order-repository/recharge-order-repository.module';
import { UserWalletLogRepositoryModule } from '@app/db/user-wallet-log-repository/user-wallet-log-repository.module';

@Global()
@Module({
    imports : [
        TypeOrmModule.forRootAsync({
            imports : [ConfigureModule],
            inject : [ConfigureService],
            useFactory : (config:ConfigureService) => {
                
                return {
                    ...config.get<TypeOrmModuleOptions>('db')
                }
            },
        }),

        SysConfigRepositoryModule,
        DeviceRepositoryModule,
        DeviceTypeRepositoryModule,
        UserRepositoryModule,
        RechargeOptionRepositoryModule,
        RechargeOrderRepositoryModule,
        WaterTestRepositoryModule,
        WaterBillsRepositoryModule,
        CleanRecordRepositoryModule,
        UserWalletLogRepositoryModule,
    ],
    providers: [DbService],
    exports : [DbService]
})
export class DbModule {}
